package com.raft.core.rpc.message;

import java.io.Serializable;

public class AppendEntriesResult implements Serializable {

    /**
	 *
	 */
	private static final long serialVersionUID = 6127856017144253504L;
	private final String rpcMessageId;
    private final int term; // 当前term，帮助Leader节点更新自己的term
    private final boolean success; // 如果为true，表示Follower节点已经添加完日志条目，或者本来就有
    // 例如，节点回复追加成功，需要推进复制进度的matchIndex或nextIndex字段，具体推进到什么位置，依赖于AppendEntries消息中的entries日志条目数组的最后一条记录的索引(考虑到entries有可能不是全部日志条目)

    public AppendEntriesResult(String rpcMessageId, int term, boolean success) {
        this.rpcMessageId = rpcMessageId;
        this.term = term;
        this.success = success;
    }

    public String getRpcMessageId() {
        return rpcMessageId;
    }

    public int getTerm() {
        return term;
    }

    public boolean isSuccess() {
        return success;
    }

    @Override
    public String toString() {
        return "AppendEntriesResult{" +
                "rpcMessageId='" + rpcMessageId + '\'' +
                ", success=" + success +
                ", term=" + term +
                '}';
    }

}
